package com.kgc.scd.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kgc.scd.bean.*;
import com.kgc.scd.mapper.OrderItemMapper;
import com.kgc.scd.service.OrderItemService;
import com.kgc.scd.util.PageSupport;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created On : 2022/6/15.
 * <p>
 * Author     : hi
 * <p>
 * Description: OrderItemServiceImpl
 */
@Service
@Slf4j
public class OrderItemServiceImpl implements OrderItemService {
    @Autowired(required = false)
    private OrderItemMapper orderItemMapper;

    /**
     *查询评论状态
     */

    @Override
    public OrderItem inquireOrderItem(String orderId) {
        OrderItemExample orderItemExample = new OrderItemExample();
        OrderItemExample.Criteria criteria = orderItemExample.createCriteria();
        criteria.andItemOrderidEqualTo(orderId);
        return orderItemMapper.selectByExample(orderItemExample).get(0);
    }

    @Override
    public void updateItem(OrderItem orderItem) {
        orderItemMapper.updateByPrimaryKeySelective(orderItem);
    }

    @Override
    public PageSupport<OrderNotComment> showNoEvaluate(String user,Integer pageSize,Integer pageNo) {
        PageHelper.startPage(pageNo,pageSize);
        List<OrderNotComment> orderNotComments = orderItemMapper.orderProducts(user);
        PageInfo<OrderNotComment> pageInfo = new PageInfo<>(orderNotComments);
        PageSupport<OrderNotComment> pageSupport = new PageSupport<>();
        // 设置分页内容
        pageSupport.setPageData(orderNotComments);
        // 设置当前页码
        pageSupport.setPageNo(pageNo);
        // 设置每页条数
        pageSupport.setPageSize(pageSize);
        // 设置总页数
        pageSupport.setTotalPage(pageInfo.getPages());
        // 设置总记录数
        pageSupport.setTotalCount((int) pageInfo.getTotal());
        return pageSupport;
    }

    @Override
    public PageSupport<OrderComment> showEvaluate(String user,Integer level,Integer time,Integer pageSize,Integer pageNo) {
        PageHelper.startPage(pageNo,pageSize);
        List<OrderComment> orderComments = orderItemMapper.OrderCommentProducts(user, level, time);
        PageInfo<OrderComment> pageInfo = new PageInfo<>(orderComments);
        PageSupport<OrderComment> pageSupport = new PageSupport<>();
        // 设置分页内容
        pageSupport.setPageData(orderComments);
        // 设置当前页码
        pageSupport.setPageNo(pageNo);
        // 设置每页条数
        pageSupport.setPageSize(pageSize);
        // 设置总页数
        pageSupport.setTotalPage(pageInfo.getPages());
        // 设置总记录数
        pageSupport.setTotalCount((int) pageInfo.getTotal());
        return pageSupport;

    }


}



